package xyz.second.auth_module.service;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.lang.NonNull;
import xyz.second.common.exception.ResponsiveException;

import java.util.List;

/**
 * 认证服务，提供用户认证(登录)所需要的接口
 * @author wjw
 */
public interface AuthService {


    /**
     * 根据账户、密码和用户类型获取用户数据，当找不到对应的User时，抛出{@link UserNotFoundException}异常
     * @param account 账户
     * @param password 密码
     * @param userType 用户类型，必须是AuthService中定义好的值
     * @throws UserNotFoundException 用户不存在时抛出该异常，经统一异常处理
     * @return 用户数据，对应User实体
     */
    @NonNull
    UserData login(
        @NonNull String account,
        @NonNull String password,
        @NonNull String userType
    );

    /**
     * 获取所有用户类型
     * @return 用户类型列表
     */
    List<UserTypeData> getAllUserType();

    @Getter
    @AllArgsConstructor
    class UserData {
        private final String account;
        private final String password;
        private final String username;
        private final String userType;
    }

    @Getter
    @AllArgsConstructor
    class UserTypeData {
        private final String name;
        private final String format;
    }

    class UserNotFoundException extends ResponsiveException {

        public UserNotFoundException(String account, String password, String userType) {
            super(HttpStatus.UNAUTHORIZED, String.format("User not found for: %s, %s, %s",
                    account, password, userType));
        }
    }

}
